#include "AudioType.h"

AudioType::AudioType() {
    replaceWords.push_back(std::string(";"));
    replaceWords.push_back(std::string(":"));
    replaceWords.push_back(std::string("."));
    replaceWords.push_back(std::string(","));
    replaceWords.push_back(std::string("("));
    replaceWords.push_back(std::string(")"));
    replaceWords.push_back(std::string("_"));
    replaceWords.push_back(std::string("-"));
    replaceWords.push_back(std::string("->"));
    replaceWords.push_back(std::string("["));
    replaceWords.push_back(std::string("/*"));
    replaceWords.push_back(std::string("*/"));
    replaceWords.push_back(std::string("/"));
    replaceWords.push_back(std::string("\\"));
    replaceWords.push_back(std::string("\\\\"));
    replaceWords.push_back(std::string("["));
    replaceWords.push_back(std::string("]"));
    replaceWords.push_back(std::string("*"));
    replaceWords.push_back(std::string("#"));
    replaceWords.push_back(std::string("\""));
    replaceWords.push_back(std::string("{"));
    replaceWords.push_back(std::string("}"));
    replaceWords.push_back(std::string("<"));
    replaceWords.push_back(std::string(">"));
    replaceWords.push_back(std::string("="));
    replaceWords.push_back(std::string("+"));
    replaceWords.push_back(std::string("-"));
    replaceWords.push_back(std::string("&"));
    replaceWords.push_back(std::string("!"));
    replaceWords.push_back(std::string("~"));

    for(int i=0;i<EXTRACTOR_getHighestKeywordTypeNumber();i++){
        extractorType.insert(i);
    }
}

void AudioType::parse(std::string path, Catalogues* catalog, EXTRACTOR_KeywordList* list) {
    EXTRACTOR_KeywordList *  aux = NULL;
    int (*pf)(int)=tolower;
    std::set<std::string>::iterator ite;
    std::set<std::string> values;
    std::vector<std::string> split;
    std::vector<std::string>::iterator splitIte;
    std::vector<std::string> listAux;
    extractList(list,values);
    // Ver que hacemos con los numeros de fecha y de numero de cancion
    values.insert(extractFileName(path));
    ite=values.begin();
    for(;ite!=values.end();ite++){
        std::string value = *ite;
        std::transform(value.begin(),value.end(),value.begin(),pf);
        replace(value);
        listAux = StaticUtils::split(value," ");
         for (splitIte = listAux.begin(); splitIte != listAux.end();) {
            StaticUtils::trimo(*splitIte);
            if (StaticUtils::isNumeric(*splitIte) || (*splitIte).empty()) {
                splitIte = listAux.erase(splitIte);
            } else {
                splitIte++;
            }
        }
        split.insert(split.end(),listAux.begin(),listAux.end());
        matchStopWords(split);
        listAux.clear();
    }
    if(!split.empty())
        catalog->agregarDocumento(path,split);
}

AudioType::~AudioType() {
    
}